const api = require('../../utils/api.js');

Page({
  data: {
    videoList: []
  },

  onLoad() {
    // 页面加载时获取视频列表
    this.loadVideoList();
  },

  // 加载视频列表
  async loadVideoList() {
    try {
      const response = await api.request('/videos');
      this.setData({
        videoList: response.videos || []
      });
    } catch (error) {
      console.error('获取视频列表失败:', error);
      wx.showToast({
        title: '获取视频列表失败',
        icon: 'none'
      });
    }
  },

  // 跳转到视频详情页面
  goToVideoDetail(e) {
    const video = e.currentTarget.dataset.video;
    wx.navigateTo({
      url: `/pages/video-detail/video-detail?id=${video.id}`
    });
  }
});